package com.maomao.maomaochong_i.fenLeiPackage;

import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import com.maomao.maomaochong_i.R;
import com.maomao.maomaochong_i.adapterPackage.MaoGridAdapter;
import com.maomao.maomaochong_i.dataBean.AllItem;
import com.maomao.maomaochong_i.productPackage.ProductMessage;

import java.util.ArrayList;

/**
 * Created by maomao on 2017/5/17.
 */

public class FenLeiPageGridFragment extends Fragment implements AdapterView.OnItemClickListener {
    private Context context;
    private FragmentManager fManager = null;
    private ArrayList<AllItem> datas = null;
    private GridView gridView;
    private BaseAdapter adapter = null;

    public FenLeiPageGridFragment(FragmentManager fManager, ArrayList<AllItem> datas, Context context) {
        this.fManager = fManager;
        this.datas = datas;
        this.context = context;
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.fenlei_frame_grid, container, false);
        gridView = (GridView) view.findViewById(R.id.frameGrid);

        //设置GridView 中的数据
        adapter = new MaoGridAdapter<AllItem>(datas, R.layout.fenlei_grid_item) {
            public void bindView(gridViewHolder holder, AllItem allItem){
                holder.setImageResource(R.id.imageView, allItem.getId());
                holder.setText(R.id.textView1, allItem.getName());
                holder.setText(R.id.textView2, allItem.getPrice());
            }
        };
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener(this);
        return view;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        view = view.findViewById(R.id.textView1);
//        String mao = ((TextView) view).getText().toString();
//        Toast.makeText(context,""+mao, Toast.LENGTH_SHORT).show();
        Intent intent = new Intent();
        intent.setClass(context,ProductMessage.class);
        context.startActivity(intent);
    }

}

